package com.example.youjingjing.electronicbalance;

import android.content.ComponentName;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;

import com.example.youjingjing.electronicbalance.service.MyIntentService;

import butterknife.ButterKnife;

/**
 * Created by youjingjing on 2017/8/4.
 */

public class Connection extends AppCompatActivity{
    private MyIntentService myIntentService;
    private MyService.MyBind myBind;
    Intent intent;
    private ServiceConnection serviceConnection = new ServiceConnection() {
        @Override
        public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
            myBind = (MyService.MyBind) iBinder;
            myBind.startDownload();
        }

        @Override
        public void onServiceDisconnected(ComponentName componentName) {

        }
    };

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);
    }


//    @OnClick(R.id.bt_dropdown)
//    public void onclick(){
//        intent = new Intent(this, MyService.class);
//        startService(intent); // 启动服务
//        bindService(intent, serviceConnection, BIND_AUTO_CREATE); // 绑定服务
//    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        unbindService(serviceConnection);
        stopService(intent);
    }
}
